/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package factura.modelo;

import java.util.Date;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Romig Sevilla
 * @version 1.0
 */
@Entity
@Table(name = "factura", catalog = "postgres", schema = "facturacion")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Factura.findAll", query = "SELECT f FROM Factura f"),
    @NamedQuery(name = "Factura.findById", query = "SELECT f FROM Factura f WHERE f.id = :id"),
    @NamedQuery(name = "Factura.findByFecha", query = "SELECT f FROM Factura f WHERE f.fecha = :fecha")})
public class Factura extends ClavePrimaria {

    private static final long serialVersionUID = 1L;
    private Date fecha;
    private Cliente idCliente;
    private Integer descuento;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    private Double iva;
    private Double totalop;
    private List<DetalleFactura> detalleFacturaList;

    public Factura() {
    }

    public Factura(Integer id) {
        this.id = id;
    }

    @Id
    @SequenceGenerator(name = "autoincremfactura", sequenceName = "facturacion.idfactura", allocationSize = 1)
    @GeneratedValue(generator = "autoincremfactura", strategy = GenerationType.SEQUENCE)
    @Column(name = "id", nullable = false)
    public Integer getId() {
        return id;
    }

    @Column(name = "fecha")
    @Temporal(TemporalType.DATE)
    public java.util.Date getFecha() {
        return fecha;
    }

    public void setFecha(java.util.Date fecha) {
        this.fecha = fecha;
    }

    @JoinColumn(name = "idcliente", referencedColumnName = "id")
    @ManyToOne
    public Cliente getIdCliente() {
        return idCliente;
    }

    public void setIdCliente(Cliente idCliente) {
        this.idCliente = idCliente;
    }

    @Column(name = "descuento")
    public Integer getDescuento() {
        return descuento;
    }

    public void setDescuento(Integer descuento) {
        this.descuento = descuento;
    }

    @Column(name = "iva")
    public Double getIva() {
        return iva;
    }

    public void setIva(Double iva) {
        this.iva = iva;
    }

    @Column(name = "totalop")
    public Double getTotalop() {
        return totalop;
    }

    public void setTotalop(Double totalop) {
        this.totalop = totalop;
    }

    @OneToMany(mappedBy = "idFactura", cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    @XmlTransient
    public List<DetalleFactura> getDetalleFacturaList() {
        return detalleFacturaList;
    }

    public void setDetalleFacturaList(List<DetalleFactura> detalleFacturaList) {
        this.detalleFacturaList = detalleFacturaList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Factura)) {
            return false;
        }
        Factura other = (Factura) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "facturacion.clases.Factura[ id=" + id + " ]";
    }
}
